<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>The Ajax 02 Page</h1>
    <button onclick="doAjaxGet()">Do Ajax Get</button>
    <button onclick="doAjaxPost()">Do Ajax Post</button>
    <button onclick="doAjaxDelete()">Do Ajax Delete</button>
    <button onclick="doAjaxUpdate()">Do Ajax Update</button>
    <div id="result"></div>

    <script>
        function doAjaxGet() {
            let xhr = new XMLHttpRequest();
            xhr.onreadystatechange=function () {
                if (xhr.readyState==4&&xhr.status==200){
                    document.getElementById("result").innerHTML=xhr.responseText;
                }
            }
            xhr.open("GET","http://localhost:8080/doAjaxGet",true);
            xhr.send(null);
            console.log("===main tread===")
        }
    </script>

    <script>
        function doAjaxPost() {
            let xhr = new XMLHttpRequest();
            xhr.onreadystatechange=function () {
                if (xhr.readyState==4&&xhr.status==200){
                    document.getElementById("result").innerHTML=xhr.responseText;
                }
            }
            xhr.open("POST","http://localhost:8080/doAjaxPost",true);
            xhr.setRequestHeader("Contest-Type","application/x-www-form-urlencoded");
            xhr.send("id=101&name=Computer&remark=Computer...");
            console.log("===main tread===")
        }
    </script>

   <script>
       function doAjaxDelete(){
           let xhr = new XMLHttpRequest();
           xhr.onreadystatechange=function(){
               if (xhr.readyState==4&&xhr.status==200){
                   document.getElementById("result").innerHTML=xhr.responseText;
               }
           }
           xhr.open("delete","http://localhost:8080/doAjaxDelete?id=101",true);
           xhr.send(null);

       }
   </script>

    <script>
        function doAjaxUpdate() {
            let xhr = new XMLHttpRequest();
            xhr.onreadystatechange=function () {
                if (xhr.readyState==4&&xhr.status==200){
                    document.getElementById("result").innerHTML=xhr.responseText;
                }
            }
            xhr.open("put","http://localhost:8080/doAjaxUpdate",true);
            xhr.setRequestHeader("Contest-Type","application/x-www-form-urlencoded")
            xhr.send("id=101&name=Book&remark=Book...");
            console.log("===main tread===")
        }
    </script>

<form enctype="application/x-www-form-urlencoded"></form>
</body>
</html>